<?php
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	//搜索
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$tip='[每个区可设置开启前端展示，关闭前端不展示]，每个区金额可自定义设定；会员可自选每个区投放一次，出局后再这个区又可以投放一次，以此类推';
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['num']){
		$psize = $_RQ['num'];
	}else{
		$psize = 15;
	}
	$total='';
	$parameter=array(
		'params'=>$params,
		'fields'=>$fields,
		'limit'=>array($pindex,$psize),
	);
	$list=pdo_getslice('jy_stpinggou_licaigroup',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['url']=custom_url('jy_stpinggou/licai.detail//id='.$item['id'],true);
		}
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			'0'=>array('op'=>'list','title'=>'倍财金区列表'),
			'1'=>array('op'=>'edit','title'=>'添加倍财金区'),
		),
		'list'=>array('data'=>'list','tip'=>$tip,'list'=>array(
			array('type'=>'string','title'=>'排序','name'=>'paixu'),
			array('name'=>'image','title'=>'区域图标','type'=>'image'),
			array('name'=>'title','title'=>'区域标题','type'=>'string'),
			array('type'=>'unitstring','unit'=>'元','title'=>'投资额度','name'=>'fee'),
			array('type'=>'unitstring','unit'=>'元','title'=>'出局获利额度','name'=>'getfee'),
			array('type'=>'unitstring','unit'=>'人','title'=>'每进N人获利出局1人','name'=>'mannum','help'=>''),
			array('name'=>'url','title'=>'链接','type'=>'copy'),
		)),
		'search_one'=>array('name'=>'title'),
	);
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_stpinggou_licaigroup',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'区域',
		'tabs'=>array(
			'0'=>array('op'=>'list','title'=>'倍财金区列表'),
			'1'=>array('op'=>'edit','title'=>'添加倍财金区'),
		),
		'edit'=>array(
			array('type'=>'string','title'=>'标题','name'=>'title', 'help'=>'' ),
			array('type'=>'image','title'=>'图标','name'=>'image', 'help'=>'' ),
			array('type'=>'string','title'=>'描述','name'=>'desc', 'help'=>'' ),
			array('type'=>'unitstring','unit'=>'元','title'=>'投资额度','name'=>'fee'),
			array('type'=>'unitstring','unit'=>'元','title'=>'出局获利额度','name'=>'getfee'),
			array('type'=>'unitstring','unit'=>'人','title'=>'每进N人获利出局1人','name'=>'mannum','help'=>''),
			array('type'=>'string','title'=>'排序','name'=>'paixu', 'help'=>'' ),
			array('type'=>'switch','title'=>'是否开启','name'=>'status', 'help'=>'' ),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'title'=>trim($postdata['title']),
		'desc'=>trim($postdata['desc']),
		'mannum'=>trim($postdata['mannum']),
		'image'=>trim($postdata['image']),
		'fee'=>trim($postdata['fee']),
		'getfee'=>trim($postdata['getfee']),
		'status'=>trim($postdata['status']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_stpinggou_licaigroup',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		exi('倍财金区修改成功！','','list');
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=TIMESTAMP;
		pdo_insert('jy_stpinggou_licaigroup',$data);
		exi('倍财金区增加成功！','','list');
	}
}

if($_RQ['op'] == 'del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_stpinggou_licaigroup',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_stpinggou_licaigroup',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			}
		}
	}
	exi('删除成功！');
}

?>